package exejava;

import java.awt.event.*;
import java.awt.*;
import org.havi.ui.*;
import org.havi.ui.event.*;
import org.dvb.ui.*;

class ContainerEnquete extends HContainer implements KeyListener {
	
	private HStaticText label1, label[];
	private MenuPrincipal pai;
	private int i = 0;
	
	public ContainerEnquete(int x, int y, int width, int height, MenuPrincipal pai) {
		super(x, y, width, height);
		this.pai = pai;
		label1 = new HStaticText("Enquete", 20, 35, 120, 35, new Font("Tiresias", Font.BOLD, 30), DVBColor.YELLOW, new DVBColor(255,255,253,0), new HDefaultTextLayoutManager());
		
		label = new HStaticText[3];
		label[0] = new HStaticText("Camila Moreno", 320, 25, 200, 35, new Font("Tiresias", Font.BOLD, 22), DVBColor.RED, new DVBColor(255,255,253,0), new HDefaultTextLayoutManager());
		label[1] = new HStaticText("Denise Regina", 320, 55, 200, 35, new Font("Tiresias", Font.BOLD, 22), DVBColor.YELLOW, new DVBColor(255,255,253,0), new HDefaultTextLayoutManager());
		label[2] = new HStaticText("Isabela Di Leli", 320, 85, 200, 35, new Font("Tiresias", Font.BOLD, 22), DVBColor.YELLOW, new DVBColor(255,255,253,0), new HDefaultTextLayoutManager());
		this.add(label1);
		this.add(label[0]);
		this.add(label[1]);
		this.add(label[2]);
		this.addKeyListener(this);
	}
	
	public void keyTyped(KeyEvent e) {
    }

    public void keyReleased(KeyEvent e) {
    }

    public void keyPressed(KeyEvent e) {
		if (e.getKeyChar()==HRcEvent.VK_UP) {
			label[i].setForeground(DVBColor.YELLOW);
			i = i == 0 ? 2 : i - 1;
			label[i].setForeground(DVBColor.RED);
			repaint();
		}
		else if (e.getKeyChar()==HRcEvent.VK_DOWN) {
			label[i].setForeground(DVBColor.YELLOW);
			i = i == 2 ? 0 : i + 1;
			label[i].setForeground(DVBColor.RED);
			repaint();
		}
		else if (e.getKeyChar()==HRcEvent.VK_ESCAPE) {
			pai.transferFocus();
		}
		else if (e.getKeyChar()==HRcEvent.VK_ENTER) {
			//ATUALIZA RESULTADOS PARCIAIS (EXEMPLO: ESCREVE NUM ARQUIVO)
			//CONFIRMA QUE JA VOTOU (PRA DESABILITAR BOTAO, QUEM SABE UM REPAINT COM UM RISCO OU UM GRANDE X VERMELGO NO NOME ENQUETE?)
			pai.votou();
			pai.transferFocus();
		}
	}
	
	public void paint(Graphics g) {
		g.setColor(new DVBColor(0, 0, 164, 255));
		g.fillRect(0,0,getWidth(),getHeight());
				
		super.paint(g);
	}
}